#include <gflags/gflags.h>

#include "gateway_server.h"
#include "log.h"

// log
DEFINE_int32(log_level, 1, "日志等级");
DEFINE_bool(mode, false, "调试模式-false, 发布模式-true");
DEFINE_string(path, "./logfile", "发布模式下日志输出到的文件路径");

// etcd
DEFINE_string(etcd_host, "http://127.0.0.1:2379", "etcd服务器地址");
DEFINE_string(base_service, "/service", "服务根目录");
DEFINE_string(file_service, "/service/file", "文件服务目录");
DEFINE_string(user_service, "/service/user", "用户服务目录");
DEFINE_string(speech_service, "/service/asr", "语音服务目录");
DEFINE_string(transmit_service, "/service/transmit", "消息转发服务目录");
DEFINE_string(message_service, "/service/message", "消息存储服务目录");
DEFINE_string(friend_service, "/service/friend", "好友服务目录");

// redis
DEFINE_string(redis_ip, "127.0.0.1", "这是服务器的IP地址，格式：127.0.0.1");
DEFINE_int32(redis_port, 6379, "这是服务器的端口, 格式: 8080");
DEFINE_int32(redis_db, 0, "库的编号: 默认0号");
DEFINE_bool(keep_alive, true, "是否进行长连接保活");

DEFINE_int32(websocket_listen_port, 9001, "websocket监听端口");
DEFINE_int32(http_listen_port, 9000, "http监听端口");


int main(int argc, char* argv[]) {
    google::ParseCommandLineFlags(&argc, &argv, true);
    chat::initLogger(FLAGS_log_level, FLAGS_mode, FLAGS_path);

    chat::GateWayServerBuilder gateway_builder;
    gateway_builder.makeServiceManager(FLAGS_file_service, FLAGS_user_service,
                                       FLAGS_speech_service, FLAGS_transmit_service,
                                       FLAGS_message_service, FLAGS_friend_service);
    gateway_builder.makeDiscoveryClient(FLAGS_etcd_host, FLAGS_base_service);
    gateway_builder.makeRedisClient(FLAGS_redis_ip, FLAGS_redis_port,
                                 FLAGS_redis_db, FLAGS_keep_alive);
    gateway_builder.makeServer(FLAGS_websocket_listen_port, FLAGS_http_listen_port);

    chat::GatewayServerPtr gateway_server = gateway_builder.build();

    gateway_server->start();

    return 0;
}